<div class="modal fade" id="ModalCreateCategory" role="dialog">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title"><?php echo __d('admin', 'New Category'); ?></h4>
			</div>
			<div class="modal-body">
				<form id="CategoryNewForm">
					<div class="form-group">
						<label form="CategoryName"><?php echo __d('admin', 'Name'); ?></label>
						<input type="text" name="name" class="form-control" placeholder="<?php echo __d('admin', 'Name'); ?>" />
					</div>
					<div class="form-group">
						<label for="CategoryParent"><?php echo __d('admin', 'Parent'); ?></label>
						<?php echo $this->Form->input('parent', array (
							'label' => false,
							'class' => 'form-control input-sm',
							'empty' => __d('admin', 'Uncategorized'),
							'options' => $categories,
							'escape' => false
						)); ?>
					</div>
					<div class="form-group">
						<input id="SubmitCategoryButton" type="button" value="<?php echo __d('admin', 'Create'); ?>" class="btn btn-primary" />
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<script>
$( document ).ready(function() {
	$( "#SubmitCategoryButton" ).click(function(e) {
		$.ajax({
			url : "<?php echo $this->Html->url("/admin/misc/create_product_category"); ?>",
			data : $("#CategoryNewForm").serialize(),
			method : 'POST',
			success : function(data, textStatus, xhr) {
				if( data.status === 1 ) {
					//var Category = data.result.Category;
					$( "#ProductCategoryId" ).empty();
					for( var cid in data.result ) {
						var category = data.result[cid];
						$( "#ProductCategoryId" ).append('<option value="' + cid + '">' + category + '</option>');
					}
					$( "#ProductCategoryId" ).val( data.category.id ).focus();
				}
				$( '#ModalCreateCategory' ).modal('hide');
			},
			dataType : "json"
		});
		e.preventDefault();
		return false;
	});
});
</script>